import 'package:flutter/material.dart';
import 'package:flutter_douban/model/knowledge_model.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';

import 'mother_knowledge_cell.dart';

class MotherKnowledgeView extends StatefulWidget {
  final List<KnowledgeModel> zhiList;
  const MotherKnowledgeView({Key? key,required this.zhiList}) : super(key: key);

  @override
  _MotherKnowledgeViewState createState() => _MotherKnowledgeViewState();
}

class _MotherKnowledgeViewState extends State<MotherKnowledgeView> {

  ScrollController? _scrollController;

  @override
  void initState() {
    super.initState();
    _scrollController = ScrollController();
  }

  @override
  void dispose() {
    _scrollController!.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {

    return Container(
      padding: EdgeInsets.only(left: 5,right: 5,top: 80),
      color: Colors.grey[100],
      child: StaggeredGridView.countBuilder(
        controller: _scrollController,
        itemCount: widget.zhiList.length,
        primary: false,
        shrinkWrap: true,
        crossAxisCount: 4,
        mainAxisSpacing: 10.0,
        crossAxisSpacing: 5.0,
        itemBuilder: (context, index) => KnowledgeCell(
          model: widget.zhiList[index],
        ),
        staggeredTileBuilder: (index) => StaggeredTile.fit(2),
      ),
    );
  }
}
